home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / interapplication comm / moreappleevents / processhelpers.c < prev    next >
Encoding:
Text File  |  2000-06-23  |  3.8 KB  |  140 lines

  1. /*
  2.     File:        ProcessHelpers.c
  3.  
  4.     Contains:    Functions to help you when working with processes.
  5.  
  6.     Written by: Andy Bachorski    
  7.  
  8.     Copyright:    Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/21/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23.  
  24. //******************************************************************************
  25. //    A private conditionals file to setup the build environment for this project.
  26.  
  27. #include "PrivateConditionals.h"
  28.  
  29.             
  30. //**********    Universal Headers        ****************************************
  31.  
  32. #include <Processes.h>
  33. #include <Types.h>
  34.  
  35.  
  36. //**********    Project Headers            ****************************************
  37.  
  38. #include "ProcessHelpers.h"
  39.  
  40.  
  41. //******************************************************************************
  42.  
  43. pascal    OSErr    FindProcessBySignature( const OSType targetType,
  44.                                         const OSType targetCreator,
  45.                                               ProcessSerialNumberPtr psnPtr )
  46. {
  47.     OSErr        anErr = noErr;
  48.     Boolean        lookingForProcess = true;
  49.     
  50.     ProcessInfoRec    infoRec;
  51.     
  52.     infoRec.processInfoLength = sizeof( ProcessInfoRec );
  53.     infoRec.processName = nil;
  54.     infoRec.processAppSpec = nil;
  55.     
  56.     psnPtr->lowLongOfPSN = kNoProcess;
  57.     psnPtr->highLongOfPSN = kNoProcess;
  58.  
  59.     while ( lookingForProcess )
  60.     {
  61.         anErr = GetNextProcess( psnPtr );
  62.         if ( anErr != noErr )
  63.         {
  64.             lookingForProcess = false;
  65.         }
  66.         else
  67.         {
  68.             anErr = GetProcessInformation( psnPtr, &infoRec );
  69.             if ( ( anErr == noErr )
  70.                  && ( infoRec.processType == targetType )
  71.                  && ( infoRec.processSignature == targetCreator ) )
  72.             {
  73.                 lookingForProcess = false;
  74.             }
  75.         }
  76.     }
  77.     
  78.     return anErr;
  79. }//end FindProcessBySignature
  80.  
  81. //******************************************************************************
  82.  
  83. pascal    OSErr    GetProcessName( const ProcessSerialNumberPtr psnPtr,
  84.                                 StringPtr processName )
  85. {
  86.     OSErr            anErr = noErr;    
  87.     ProcessInfoRec    infoRec;
  88.     
  89.     infoRec.processInfoLength = sizeof( ProcessInfoRec );
  90.     infoRec.processName = processName;
  91.     infoRec.processAppSpec = nil;
  92.     
  93.     anErr = GetProcessInformation( psnPtr, &infoRec );
  94.     
  95.     return anErr;
  96. }//end FindProcessBySignature
  97.  
  98. //******************************************************************************
  99.  
  100. pascal    OSErr    GetProcessTypeSignature( const ProcessSerialNumberPtr psnPtr,
  101.                                          OSType *processType,
  102.                                          OSType *processSignature )
  103. {
  104.     OSErr            anErr = noErr;    
  105.     ProcessInfoRec    infoRec;
  106.     
  107.     infoRec.processInfoLength = sizeof( ProcessInfoRec );
  108.     infoRec.processName = nil;
  109.     infoRec.processAppSpec = nil;
  110.     
  111.     anErr = GetProcessInformation( psnPtr, &infoRec );
  112.     if ( anErr == noErr )
  113.     {
  114.         *processType = infoRec.processType;
  115.         *processSignature = infoRec.processSignature;
  116.     }
  117.     
  118.     return anErr;
  119. }//end FindProcessBySignature
  120.  
  121. //******************************************************************************
  122.  
  123. // Return an FSSpec to the current process
  124.  
  125. pascal    OSErr    GetCurrentProcessFSSpec( FSSpec *spec )
  126. {
  127.     ProcessSerialNumber    currentPSN;
  128.     ProcessInfoRec        info;
  129.     
  130.     /* Get the current process' FSSpec with GetProcessInformation */
  131.     currentPSN.highLongOfPSN = 0;
  132.     currentPSN.lowLongOfPSN = kCurrentProcess;
  133.     info.processInfoLength = sizeof(ProcessInfoRec);
  134.     info.processName = NULL;    /* we don't need the process name */
  135.     info.processAppSpec = spec;
  136.     return ( GetProcessInformation(¤tPSN, &info) );
  137. }
  138.  
  139. //******************************************************************************
  140.